home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gnumake / pdmake.zoo / main.c < prev    next >
C/C++ Source or Header  |  1991-09-25  |  6KB  |  264 lines

  1.     /***************************************************************\
  2.     *                                *
  3.     *  PDMAKE, Atari ST version                    *
  4.     *                                *
  5.     *  Adapted from mod.sources Vol 7 Issue 71, 1986-12-03.        *
  6.     *                                *
  7.     *  This port makes extensive use of the original net.sources    *
  8.     *  port by Jwahar Bammi.                    *
  9.     *                                *
  10.     *      Ton van Overbeek                        *
  11.     *      Email: TPC862@ESTEC.BITNET                *
  12.     *             TPC862%ESTEC.BITNET@WISCVM.WISC.EDU    (ARPA)    *
  13.     *             ...!mcvax!tpc862%estec.bitnet   (UUCP Europe)    *
  14.     *             ...!ucbvax!tpc862%estec.bitnet  (UUCP U.S.A.)    *
  15.     *             71450,3537  (CompuServe)                *
  16.     *                                *
  17.     \***************************************************************/
  18.  
  19. /*
  20.  *    make [-f makefile] [-ins] [target(s) ...]
  21.  *
  22.  *    (Better than EON mk but not quite as good as UNIX make)
  23.  *
  24.  *    -f makefile name
  25.  *    -i ignore exit status
  26.  *    -n Pretend to make
  27.  *    -p Print all macros & targets
  28.  *    -q Question up-to-dateness of target.  Return exit status 1 if not
  29.  *    -r Don't not use inbuilt rules
  30.  *    -s Make silently
  31.  *    -t Touch files instead of making them
  32.  *    -m Change memory requirements (EON only)
  33.  */
  34.  
  35. #include <stdio.h>
  36. #include "h.h"
  37.  
  38. #ifdef unix
  39. #include <sys/errno.h>
  40. #endif
  41. #ifdef eon
  42. #include <sys/err.h>
  43. #endif
  44. #ifdef os9
  45. #include <errno.h>
  46. #endif
  47. #ifdef ATARIST
  48. #include "astat.h"
  49. #endif
  50.  
  51. #ifdef eon
  52. #define MEMSPACE    (16384)
  53. #endif
  54.  
  55.  
  56. char *        myname;
  57. char *        makefile = "";        /*  The make file  */
  58. #ifdef eon
  59. unsigned        memspace = MEMSPACE;
  60. #endif
  61.  
  62. FILE *        ifd;            /*  Input file desciptor  */
  63. bool        domake = TRUE;        /*  Go through the motions option  */
  64. bool        ignore = FALSE;        /*  Ignore exit status option  */
  65. bool        silent = FALSE;        /*  Silent option  */
  66. bool        print = FALSE;        /*  Print debuging information  */
  67. bool        rules = TRUE;        /*  Use inbuilt rules  */
  68. bool        dotouch = FALSE;    /*  Touch files instead of making  */
  69. bool        quest = FALSE;        /*  Question up-to-dateness of file  */
  70.  
  71. void
  72. main(argc, argv)
  73. int        argc;
  74. char **        argv;
  75. {
  76.     register char *    p;        /*  For argument processing  */
  77.     int            estat = 0;    /*  For question  */
  78.     register struct name *    np;
  79.  
  80. #ifdef ATARIST
  81.     myname = "make";            /*  TOS doesn't pass argv[0]  */
  82.     argc--;  argv++;
  83. #else
  84.     myname = (argc-- < 1) ? "make" : *argv++;
  85. #endif
  86.  
  87.     while ((argc > 0) && (**argv == '-'))
  88.     {
  89.         argc--;                /*  One less to process  */
  90.         p = *argv++;            /*  Now processing this one  */
  91.  
  92.         while (*++p != '\0')
  93.         {
  94.             switch(*p)
  95.             {
  96.             case 'f':            /*  Alternate file name  */
  97.             case 'F':
  98.                 if (*++p == '\0')
  99.                 {
  100.                     if (argc-- <= 0)
  101.                         usage();
  102.                     p = *argv++;
  103.                 }
  104.                 makefile = p;
  105.                 goto end_of_args;
  106. #ifdef eon
  107.             case 'm':            /*  Change space requirements  */
  108.                 if (*++p == '\0')
  109.                 {
  110.                     if (argc-- <= 0)
  111.                         usage();
  112.                     p = *argv++;
  113.                 }
  114.                 memspace = atoi(p);
  115.                 goto end_of_args;
  116. #endif
  117.             case 'n':            /*  Pretend mode  */
  118.             case 'N':
  119.                 domake = FALSE;
  120.                 break;
  121.             case 'i':            /*  Ignore fault mode  */
  122.             case 'I':
  123.                 ignore = TRUE;
  124.                 break;
  125.             case 's':            /*  Silent about commands  */
  126.             case 'S':
  127.                 silent = TRUE;
  128.                 break;
  129.             case 'p':
  130.             case 'P':
  131.                 print = TRUE;
  132.                 break;
  133.             case 'r':
  134.             case 'R':
  135.                 rules = FALSE;
  136.                 break;
  137.             case 't':
  138.             case 'T':
  139.                 dotouch = TRUE;
  140.                 break;
  141.             case 'q':
  142.             case 'Q':
  143.                 quest = TRUE;
  144.                 break;
  145.             default:    /*  Wrong option  */
  146.                 usage();
  147.             }
  148.         }
  149.     end_of_args:;
  150.     }
  151.  
  152. #ifdef eon
  153.     if (initalloc(memspace) == 0xffff)    /*  Must get memory for alloc  */
  154.         fatal("Cannot initalloc memory");
  155. #endif
  156.  
  157.     if (strcmp(makefile, "-") == 0)    /*  Can use stdin as makefile  */
  158.         ifd = stdin;
  159.     else
  160.         if (*makefile == '\0')        /*  If no file, then use default */
  161.         {
  162.             if ((ifd = fopen(DEFN1, "r")) == (FILE *)0)
  163. #ifdef eon
  164.                 if (errno != ER_NOTF)
  165.                     fatal("Can't open %s; error %02x", DEFN1, errno);
  166. #endif
  167. #ifdef unix
  168.                 if (errno != ENOENT)
  169.                     fatal("Can't open %s; error %02x", DEFN1, errno);
  170. #endif
  171. #ifdef ATARIST
  172.                 fatal("Can't open %s", DEFN1);
  173. #endif
  174. #ifdef os9
  175.                 fatal("Can't open %s", DEFN1);
  176. #endif
  177. #ifndef os9
  178. #ifdef ATARIST
  179. #ifdef __GNUC__
  180.             if ((ifd == (FILE *)0)
  181.                   && ((ifd = fopen(DEFN2, "r")) == (FILE *)0))
  182.                 fatal("Can't open %s", DEFN2);
  183. #endif
  184. #endif
  185. #endif
  186.         }
  187.         else
  188.             if ((ifd = fopen(makefile, "r")) == (FILE *)0)
  189.                 fatal("Can't open %s", makefile);
  190.  
  191.     makerules();
  192.  
  193.     setmacro("$", "$");
  194.  
  195.     while (argc && (p = index(*argv, '=')))
  196.     {
  197.         char        c;
  198.  
  199.         c = *p;
  200.         *p = '\0';
  201.         setmacro(*argv, p+1);
  202.         *p = c;
  203.  
  204.         argv++;
  205.         argc--;
  206.     }
  207.  
  208.     input(ifd);        /*  Input all the gunga  */
  209.     fclose(ifd);    /*  Finished with makefile  */
  210.     lineno = 0;        /*  Any calls to error now print no line number */
  211.  
  212.     if (print)
  213.         prt();        /*  Print out structures  */
  214.  
  215.     np = newname(".SILENT");
  216.     if (np->n_flag & N_TARG)
  217.         silent = TRUE;
  218.  
  219.     np = newname(".IGNORE");
  220.     if (np->n_flag & N_TARG)
  221.         ignore = TRUE;
  222.  
  223.     precious();
  224.  
  225.     if (!firstname)
  226.         fatal("No targets defined");
  227.  
  228.     circh();        /*  Check circles in target definitions  */
  229.  
  230.     if (!argc)
  231.         estat = make(firstname, 0);
  232.     else while (argc--)
  233.     {
  234.         if (!print && !silent && strcmp(*argv, "love") == 0)
  235.             printf("Not war!\n");
  236.         estat |= make(newname(*argv++), 0);
  237.     }
  238.  
  239.     if (quest)
  240.         exit(estat);
  241.     else
  242.         exit(0);
  243. }
  244.  
  245.  
  246. usage()
  247. {
  248.     fprintf(stderr, "Usage: %s [-f makefile] [-inpqrst] [macro=val ...]\
  249.  [target(s) ...]\n", myname);
  250.     exit(1);
  251. }
  252.  
  253.  
  254. void
  255. fatal(msg, a1, a2, a3, a4, a5, a6)
  256. char    *msg;
  257. {
  258.     fprintf(stderr, "%s: ", myname);
  259.     fprintf(stderr, msg, a1, a2, a3, a4, a5, a6);
  260.     fputc('\n', stderr);
  261.     exit(1);
  262. }
  263.  
  264.